package view.room;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import constants.Constants;
import controllers.BookingController;
import controllers.RoomController;
import entity.Booking;
import entity.Customer;
import entity.Room;

class RoomInfo extends JPanel{
	private static final long serialVersionUID = 1L;

	JLabel btRoomId 		= new JLabel("PHÒNG");
	JTextField tfRoomType           = new JTextField(15);
	JTextField tfStatus		= new JTextField(15);
	JTextField tfPrice		= new JTextField(15);
	JTextField tfCustomerId         = new JTextField(15);
	JTextField tfCustomer           = new JTextField(15);
	JTextField tfCheckID            = new JTextField(15);
	JTextField tfInDate		= new JTextField(15);
	JTextField tfOutDate            = new JTextField(15);
	JTextField tfPhone		= new JTextField(15);
	
       
        ArrayList<Room> room = RoomController.getAll();
	String[] status = Constants.STATUS_NAME;
	
	public RoomInfo(){
		setPreferredSize(new Dimension(10, 100));
		initUI();
	}
	
	public void initUI(){
		setLayout(new BorderLayout());
		setBorder(BorderFactory.createLineBorder(Color.GRAY));
		
		JPanel jpButton = new JPanel(new BorderLayout());
		jpButton.setBorder(new EmptyBorder(5,5,5,5));
		jpButton.setBackground(Color.WHITE);
		btRoomId.setPreferredSize(new Dimension(100,100));
		btRoomId.setBorder(BorderFactory.createLineBorder(Color.GRAY));
		btRoomId.setVerticalAlignment(JLabel.CENTER);
		btRoomId.setHorizontalAlignment(JLabel.CENTER);
		jpButton.add(btRoomId);
		add(jpButton, BorderLayout.WEST);
		
		
		JPanel jpGrid = new JPanel(new GridLayout(3,6,5, 5));
		jpGrid.setBorder(new EmptyBorder(10, 20, 10, 20));
		jpGrid.setBackground(Color.WHITE);
		jpGrid.add(new JLabel("Loại phòng"));
		jpGrid.add(tfRoomType);
		jpGrid.add(new JLabel("Giá phòng"));
		jpGrid.add(tfPrice);
		jpGrid.add(new JLabel("Tình trạng"));
		jpGrid.add(tfStatus);
		jpGrid.add(new JLabel("Mã khách hàng"));
		jpGrid.add(tfCustomerId);
		jpGrid.add(new JLabel("Tên khách hàng"));
		jpGrid.add(tfCustomer);
		jpGrid.add(new JLabel("Liên hệ"));
		jpGrid.add(tfPhone);
		jpGrid.add(new JLabel("Mã hóa đơn"));
		jpGrid.add(tfCheckID);
		jpGrid.add(new JLabel("Ngày đến"));
		jpGrid.add(tfInDate);
		jpGrid.add(new JLabel("Ngày đi"));
		jpGrid.add(tfOutDate);
		add(jpGrid, BorderLayout.CENTER);
		
		tfRoomType	.setEditable(false);
		tfStatus	.setEditable(false);
		tfPrice		.setEditable(false);
		tfCustomerId.setEditable(false);
		tfCustomer	.setEditable(false);
		tfCheckID	.setEditable(false);
		tfInDate	.setEditable(false);
		tfOutDate	.setEditable(false);
		tfPhone		.setEditable(false);
	}
	
	public void updateRoom(int roomId){
		if (roomId<0)
			btRoomId.setText("ROOM");
		else {
                        btRoomId.setText(room.get(roomId).getName());
			tfRoomType.setText(room.get(roomId).getRoomtype().getName());
			tfStatus.setText(status[room.get(roomId).getStatus()]);
			tfPrice.setText(new Integer(room.get(roomId).getRoomtype().getCost()).toString());                     
                        if(room.get(roomId).getStatus()!= Constants.EMPTY){
                                Customer customer =BookingController.getCustomerByRoom(room.get(roomId).getId()); 
                                tfCustomer.setText(customer.getName());
                                tfCustomerId.setText(new Integer(customer.getId()).toString());
                                tfInDate.setText(customer.getInfo().getCheckin());
                                tfOutDate.setText(customer.getInfo().getCheckout());
                                tfPhone.setText(customer.getPhone());
                          
                        }else{                       
                           clearRoom();
                        }
                        
		}
	}
        private void clearRoom(){
                            tfCustomer.setText("");
                            tfCustomerId.setText("");
                            tfInDate.setText("");
                            tfOutDate.setText("");
                            tfPhone.setText("");
        
        }
}